/**
 * @author <a href="mailto:gunn.duncan@gmail.com">Duncan Gunn</a>
 * @version 1.0a
 * */

/** Creates a DialogView class.
 * @class Represents a Dialog View, providing a colorbox wrapper around an HTML div.
 * http://colorpowered.com/colorbox/
 * */
function DialogView() {
  var _element;

  var _btnSave;
  var _btnCancel;
  var _controller;

}

/**
 * Initializer.
 * @param controller The Entity GridController.
 * @param element The HTML div element which holds the dialog HTML.
 * @param btnSaveElement The HTML element representing the Save button.
 * @param btnCancelElement The HTML element representing the Cancel button.
 */
DialogView.prototype.initialize = function(controller, element, btnSaveElement, btnCancelElement){
  this._element = element;
  this._controller = controller;
  this._btnSave = btnSaveElement;
  this._btnCancel = btnCancelElement;

  $(this._btnSave).bind("click", createMethodReference(this, "handleSave"));
  $(this._btnCancel).bind("click", createMethodReference(this, "handleCancel"));
}

/**
 * @event
 * Save handler.
 */
DialogView.prototype.handleSave = function () {
    this._controller.Save();
}

/**
 * @event
 * Cancel handler.
 */
DialogView.prototype.handleCancel = function () {
    this._controller.Cancel();
}

/**
 * @event
 * Close handler.
 */
DialogView.prototype.closeDialog = function(){
  $(this._element).colorbox.close();
}

/**
 * Show the dialog.
 */
DialogView.prototype.show = function(){
  var ele = this._element;
  $(this._element).show();
  $().colorbox(
      {
          inline: true,
          href: this._element,
          open: true,
          innerWidth: 400,
          title: true,
          opacity: "0.50",
          onClosed: function ()
          { //cannot use keyword 'this' inside this function - different context - different meaning!!
            $(ele).hide();
          }
      });
}